<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of follow
 *
 * @author Andi
 */
include_once("database.php");
include_once 'notification.php';

class follow extends database {
    //put your code here

    function  __construct() {
        $this->connect();
    }


    function addFollowing($user_name,$user_name_following){
        $sql = "INSERT INTO follow (user_name,user_name_following) VALUE ('$user_name','$user_name_following')";
        mysql_query($sql);
        $notif = new notification();
        $notifBody = $user_name .' has followed you' ;
        $notif->addNotif($user_name_following, $notifBody);
    }

    function showFollowing($user_name){
        $sql = "SELECT user_name_following,url_photo FROM follow,user WHERE follow.user_name = '$user_name' AND user_name_following = user.user_name";
        $result = mysql_query($sql);
        return $result;
    }

    function showFollowed($user_name){
        //$sql = "SELECT user_name_following,url_photo FROM follow,user WHERE follow.user_name = '$user_name' AND user_name_following = user.user_name";
        $sql = "SELECT follow.user_name AS followed,url_photo FROM follow,user WHERE follow.user_name_following = '$user_name' AND follow.user_name = user.user_name";
        $result = mysql_query($sql);
        return $result;
    }

    function deleteFollowing($user_name,$user_name_following){
        $sql = "DELETE FROM follow WHERE user_name = '$user_name' AND user_name_following = '$user_name_following'";
        $result = mysql_query($sql);
    }

    function isFollowing($user_name,$user_name_following){
        $result = $this->showFollowed($user_name);
        $following = false;
        while($row = mysql_fetch_array($result)){
            if ($user_name_following == $row["followed"]){
                $following = true;
                break;
            }
        }
        return $following;
    }

}
?>
